package com.wb.web.controller.exams;


import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.vo.*;
import com.wb.system.domain.ExamsEntity;
import com.wb.system.domain.ExamsTypeEntity;
import com.wb.system.service.ExamsService;
import com.wb.system.service.ExamsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("examstype")
@Api(tags = "考试大类表")
public class ExamsTypeController extends BaseController {
    @Autowired
    private ExamsTypeService examsTypeService;

    @PostMapping("/list")
    @ApiOperation("考试大类列表")
    public TableDataInfo list(@RequestBody ExamsTypeModelVO examstypeModelVO) {
        startPage();
        List<ExamsTypeEntity> list = examsTypeService.selectExamsTypeList(examstypeModelVO);
        return getDataTable(list);
    }


    @GetMapping("/{id}")
    @ApiOperation("获取考试大类详情")
    public AjaxResult get(@PathVariable("id") Long id) {
        return AjaxResult.success(examsTypeService.selectById(id));
    }

    @PostMapping("/add")
    @ApiOperation("考试大类创建")
    public AjaxResult add(@Valid @RequestBody ExamsTypeEntity examsTypeModelVO) {
        ExamsTypeEntity examsTypeEntity = new ExamsTypeEntity();
        BeanUtils.copyProperties(examsTypeModelVO, examsTypeEntity);
        examsTypeService.saveExamsType(examsTypeEntity);
        return AjaxResult.success();
    }


    @PostMapping("/update")
    @ApiOperation("更新考试大类")
    public AjaxResult update(@RequestBody ExamsTypeEntity examsTypeModelVO) {
        ExamsTypeEntity examsTypeEntity = new ExamsTypeEntity();
        BeanUtils.copyProperties(examsTypeModelVO, examsTypeEntity);
       // examsTypeEntity.setUpdateBy(getUsername());
        examsTypeService.updateExamsTypeById(examsTypeEntity);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteAll")
    @ApiOperation("删除All")
    public AjaxResult deleteAll(@RequestBody DeleteRequest request) {
        examsTypeService.removeExamsTypeByIds(request.getIds());
        return AjaxResult.success();
    }
}
